<%@ page isELIgnored="false" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>

<head>
    <base href="<%=request.getContextPath() %>/">
    <title>投票列表</title>
    <link rel="stylesheet" href="css/addNewtp.css" />
    <script type="text/javascript" src="js/jquery-1.x.js"></script>
    <script type="text/javascript" src="js/changeH.js"></script>
    <style>
        table {
            text-align: center;
            width: 100%;
            margin: 0;
        }
    </style>
    <script type="text/javascript">
        function deleteVote(articleid) {
            if (confirm('确定要删除吗？')) {
                $.ajax({
                    url: 'articleListServlet',
                    type: 'GET',
                    data: { flag: 'del', articleid: articleid },
                    success: function(response) {
                        alert('删除成功');
                        location.reload(); // Reload the page to reflect changes
                    },
                    error: function(xhr, status, error) {
                        alert('删除失败: ' + error);
                    }
                });
            }
        }
    </script>
</head>

<body>
    <div id="pc">
        <div class="head">
            <div class="navBox">
                <div class="logo">
                    <input type="image" src="img/headlogo.png" style="margin-left:200px;width:300px;height:80px" />
                </div>
                <div class="nav">
                    <ul>
                        <li id="din">
                            <a href="/VoteWeb/articleListServlet">投票列表</a>
                        </li>
                        <li class="seleLi">
                            <a href="admin/addNewtp.jsp">添加新投票</a>
                        </li>
                        <li>
                            <a href="articleListServlet?flag=me">维护</a>
                        </li>
                        <li>
                            <a href="Statistics">统计分析</a>
                        </li>
                    </ul>
                    <div class="an">
                        <a class="esta" href="javascript:(0)">你好，${sessionScope.username}</a>
                    </div>
                    <div class="an3"><a href="/VoteWeb/logout">注销</a></div>
                </div>
            </div>
        </div>
        <div class="third">
            <div style="margin: 30px;">
                <form action="articleListServlet?flag=search" method="post">
                    <input type="search" name="key" placeholder="投票内容">
                    <button type="submit">查询</button>
                </form>
            </div>
            <table border="1">
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>投票内容</th>
                        <th>类型</th>
                        <th>创建时间</th>
						<th>发布人</th>	
						<th>已参与投票数</th>	
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach var="item" items="${list}">
                        <tr>
                            <td>${item.articleid}</td>
                            <td>${item.title}</td>
                            <td>
                                <c:choose>
                                    <c:when test="${item.type == '0'}">
                                        单选
                                    </c:when>
                                    <c:when test="${item.type == '1'}">
                                        多选
                                    </c:when>
                                    <c:otherwise>
                                        未知
                                    </c:otherwise>
                                </c:choose>
                            </td>
                            <td>${item.createTime}</td>
							<td>${item.userId}</td>
							<td>${item.voteNum}</td>
                            <td>
                                <c:choose>
                                    <c:when test="${item.num == 1}">
                                        <button disabled>已参与</button>
                                    </c:when>
                                    <c:when test="${item.num == 0}">
                                        <a href="attendVoteServlet?articleid=${item.articleid}" class="p3" target="mainframe"><button>我要参与</button></a>
                                    </c:when>
                                    <c:otherwise>
                                        未知
                                    </c:otherwise>
                                </c:choose>
                                <c:choose>
                                    <c:when test="${del}">
                                        <button onclick="deleteVote(${item.articleid})">删除</button>
                                    </c:when>
                                    <c:otherwise>
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
    </div>
    <div class="bottom"></div>
</body>

</html>
